//
//  TZDetailVc.m
//  BSBDJ
//
//  Created by user on 16/5/28.
//  Copyright © 2016年 Burning. All rights reserved.
//

#import "TZDetailVc.h"
#import "TZShowDetailCell.h"
#import "TZCommentItem.h"
#import "TZDataItem.h"
#import "TZUserItem.h"
#import "TZShowCell.h"
#import "TZHeaderView.h"
@interface TZDetailVc()
@property (nonatomic, strong) NSMutableArray *commentList;

@property (nonatomic, weak) TZHeaderView *headerView;
@end


@implementation TZDetailVc

static NSString *ID = @"detailcell";

- (TZHeaderView *)headerView{
    if (_headerView == nil) {
        TZHeaderView *headerView = [[TZHeaderView alloc] init];
        headerView.frame = CGRectMake(0, 0, TZScreenW, 300);
        _headerView = headerView;
    }
    return _headerView;
}

- (NSMutableArray *)commentList{
    if (_commentList == nil) {
        _commentList = [NSMutableArray array];
    }
    return _commentList;
}

- (void)viewDidLoad{
    [super viewDidLoad];

    [self setupUI];
    [self requestComment];
    NSLog(@"%@",self.data_id);
}


- (void)requestComment{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"data_id"] = self.data_id;
        [HttpRequestList requestEssenceDetail:detailPath paramaters:parameters success:^(TZCommentItem *commentItem) {
            
            NSLog(@"%d",commentItem.hot.count);
    
            
            [self.commentList addObjectsFromArray:commentItem.data];

            [self.tableView reloadData];
            self.tableView.tableHeaderView = self.headerView;

        } failure:^(NSError *error) {
            NSLog(@"%@",error);
        }];
}

- (void)setupUI{
    self.title = @"评论";
    self.tableView.backgroundColor = XMGColor(244, 244, 244);
    self.tableView.estimatedRowHeight = 44;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"TZShowDetailCell" bundle:nil] forCellReuseIdentifier:ID];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.commentList.count;
}
#pragma mark --------------
#pragma mark 数据源TableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TZShowDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.dataItem = self.commentList[indexPath.row];
    return cell;
}



- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
 
    self.tableView.tableHeaderView = self.headerView;

}




@end
